package org.example.day20240903文件操作.jinyong;

import java.io.*;
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws IOException {
        FileReader fileReader = new FileReader("金庸07鹿鼎记.txt");
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        FileReader fileReader1 = new FileReader("jinyong_all_person.txt");
        BufferedReader nameReader = new BufferedReader(fileReader1);
        bufferedReader.readLine();
        bufferedReader.readLine();
        bufferedReader.readLine();
        bufferedReader.readLine();
        bufferedReader.readLine();
        bufferedReader.readLine();
        String line = nameReader.readLine();
        Set<String> nameLists = new HashSet<>();
        while (line != null){
            nameLists.add(line);
            line = nameReader.readLine();
        }

        FileWriter fileWriter1 = new FileWriter("金庸07鹿鼎记人物关系.txt");
        BufferedWriter outBufferedWriter = new BufferedWriter(fileWriter1);

        String msgLine = bufferedReader.readLine();
        while (msgLine != null){
            boolean isEmpty = false;
            for (String nameList : nameLists){
                if(msgLine.indexOf(nameList)>0){
                    outBufferedWriter.write(nameList+" ");
                    isEmpty = true;
                }
            }
            if (isEmpty == true){
                outBufferedWriter.write("\n");
            }
            msgLine = bufferedReader.readLine();
        }
        outBufferedWriter.close();
        bufferedReader.close();
    }
}
